﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VersionComparer.Base;
using VersionComparer.Configuration;

namespace VersionComparer.UI
{
    public class AllSettingsControl : UserControl, IContainedControl
    {
        private TabControl tabControl1;
        private TabPage tabPage1;
        private TabPage tabPage2;

        List<SettingsControl> settingsControls = new List<SettingsControl>();
        public AllSettingsControl():base()
        {
            InitializeComponent();
            tabControl1.TabPages.Clear();
            foreach (var type in AddInsManager.Current.GetObjectsOfType<SettingsBase>())
            {
                SettingsBase settings = SettingsBase.GetSettings(type);
                if (settings != null)
                {
                    TabPage page = new TabPage(settings.Name);
                    SettingsControl control = new SettingsControl();
                    settingsControls.Add(control);
                    control.Settings = settings;
                    control.Dock = DockStyle.Fill;
                    page.Controls.Add(control);
                    tabControl1.TabPages.Add(page);
                }
            }
        }
        private void InitializeComponent()
        {
            this.tabControl1 = new System.Windows.Forms.TabControl();
            this.tabPage1 = new System.Windows.Forms.TabPage();
            this.tabPage2 = new System.Windows.Forms.TabPage();
            this.tabControl1.SuspendLayout();
            this.SuspendLayout();
            // 
            // tabControl1
            // 
            this.tabControl1.Controls.Add(this.tabPage1);
            this.tabControl1.Controls.Add(this.tabPage2);
            this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.tabControl1.Location = new System.Drawing.Point(0, 0);
            this.tabControl1.Name = "tabControl1";
            this.tabControl1.SelectedIndex = 0;
            this.tabControl1.Size = new System.Drawing.Size(284, 269);
            this.tabControl1.TabIndex = 0;
            // 
            // tabPage1
            // 
            this.tabPage1.Location = new System.Drawing.Point(4, 22);
            this.tabPage1.Name = "tabPage1";
            this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage1.Size = new System.Drawing.Size(276, 243);
            this.tabPage1.TabIndex = 0;
            this.tabPage1.Text = "tabPage1";
            this.tabPage1.UseVisualStyleBackColor = true;
            // 
            // tabPage2
            // 
            this.tabPage2.Location = new System.Drawing.Point(4, 22);
            this.tabPage2.Name = "tabPage2";
            this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
            this.tabPage2.Size = new System.Drawing.Size(192, 74);
            this.tabPage2.TabIndex = 1;
            this.tabPage2.Text = "tabPage2";
            this.tabPage2.UseVisualStyleBackColor = true;
            // 
            // AllSettingsControl
            // 
            this.Controls.Add(this.tabControl1);
            this.Name = "AllSettingsControl";
            this.Size = new System.Drawing.Size(284, 269);
            this.tabControl1.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        string IContainedControl.Text
        {
            get 
            {
                return Resources.Resources.SettingsControlCaption;
            }
        }


        public void Close(bool acceptChanges)
        {
            foreach (var control in settingsControls)
                control.Close(acceptChanges);
        }
    }
}
